package br.com.aquinoevasconcelos.servlets.modeloContrato;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.aquinoevasconcelos.fachada.Fachada;
import br.com.aquinoevasconcelos.modelos.ModeloContrato;

/**
 * Servlet implementation class ListaModeloContrato
 */
@WebServlet("/ListaModeloContrato")
public class ListaModeloContrato extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public ListaModeloContrato() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		Fachada fachada = Fachada.getInstancia();
		ModeloContrato mc = new ModeloContrato();
		ArrayList<ModeloContrato> modelosContratos;
		
		try {
		
			
			modelosContratos = (ArrayList<ModeloContrato>) fachada.listaModeloContrato();
			request.setAttribute("listaModelos", modelosContratos);
			
			RequestDispatcher rd = request
					.getRequestDispatcher("modelos_formularios.jsp");
			rd.forward(request, response);
			
			request.getRequestDispatcher("modelos_formularios.jsp").include(
					request, response);
			
		} catch (Exception e) {
			
			RequestDispatcher rd = request
					.getRequestDispatcher("pagina_erro/erro.jsp");
			rd.forward(request, response);
			e.printStackTrace();
		}

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
